import { defineStore } from "pinia"
import { ref } from 'vue'
//用户模块 token setToken removeToken
export const useUserStore = defineStore('user', () => {
    const token = ref('')  //token
    const jobNumber =ref('')  //用户工号
    const name = ref('')  //用户姓名
    const roleId = ref()  //用户角色ID
    const setToken = (newToken) => {
        token.value = newToken
    }
    const setName = (newName) => {
        name.value = newName
    }
    const setRoleId = (newRoleId) => {
        roleId.value = newRoleId
    }
    const setJobNumber = (newJobNumber) => {
        jobNumber.value = newJobNumber
    }
    const removeToken = () => {
        token.value = ''
    }
    const removeName = () => {
        name.value = ''
    }
    const removeRoleId = () => {
        roleId.value = null
    }
    const removeJobNumber = () => {
        jobNumber.value = null
    }
    return {
        token,
        name,
        roleId,
        jobNumber,
        setToken,
        setName,
        setRoleId,
        setJobNumber,
        removeToken,
        removeName,
        removeRoleId,
        removeJobNumber,
    }
},{
    persist: true  //持久化
})
